package com.gzgy.ustore.api.dao.impl;

import com.gzgy.ustore.api.common.jdbc.StatementParameter;
import com.gzgy.ustore.api.dao.DvcGroupDao;
import com.gzgy.ustore.api.model.DvcGroupList;
import com.gzgy.ustore.api.model.DvcGroupListTree;
import com.ustore.model.DvcGroup;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DvcGroupDaoImpl extends AbstractBaseDao<DvcGroup> implements DvcGroupDao {
    @Override
    public List<DvcGroupListTree> dvcGroupListTree(Integer companyId) {

        String sql = "SELECT ID AS dvcGroupCode , DVC_GROUP_NAME AS name FROM " +this.tableName+ " WHERE COMPANY_ID = ? AND IS_DELETED = 0 ";

        StatementParameter parameter = new StatementParameter();
        parameter.setInt(companyId);

        return this.queryForList(sql,DvcGroupListTree.class,parameter);
    }

    @Override
    public List<DvcGroupList> dvcGroupList(Integer companyId) {


        StringBuffer sb = new StringBuffer();
        sb.append("SELECT id as dvcGroupId,DVC_GROUP_NAME,REMARK,IFNULL(UPDATED_BY,CREATED_BY) as lastModifyUser, ");
        sb.append(" IFNULL(UPDATED_TIME,CREATED_TIME) as lastModifyTime ");
        sb.append(" FROM dvc_group where COMPANY_ID =? and IS_DELETED = 0");

        StatementParameter parameter = new StatementParameter();
        parameter.setInt(companyId);

        return this.queryForList(sb.toString(),DvcGroupList.class,parameter);
    }
}
